const API_BASE_URL = 'http://localhost:3000/api';

export const reminderApi = {
    async getAllReminders() {
        try {
            const response = await fetch(`${API_BASE_URL}/reminders`);
            if (!response.ok) {
                throw new Error('获取提醒列表失败');
            }
            return await response.json();
        } catch (error) {
            console.error('获取提醒列表错误:', error);
            throw error;
        }
    },

    async addReminder(reminder) {
        try {
            const response = await fetch(`${API_BASE_URL}/reminders`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(reminder)
            });
            if (!response.ok) {
                throw new Error('添加提醒失败');
            }
            return await response.json();
        } catch (error) {
            console.error('添加提醒错误:', error);
            throw error;
        }
    },

    async deleteReminder(id) {
        try {
            const response = await fetch(`${API_BASE_URL}/reminders/${id}`, {
                method: 'DELETE'
            });
            if (!response.ok) {
                throw new Error('删除提醒失败');
            }
            return true;
        } catch (error) {
            console.error('删除提醒错误:', error);
            throw error;
        }
    }
};
    